package it.pecuswap.backend.business;

import it.pecuswap.backend.delegate.UsersDelegate;
import it.pecuswap.backend.entities.Users;
import it.pecuswap.backend.exceptions.EntityHomeException;
import it.pecuswap.backend.wrappers.UserWrapper;
import it.pecuswap.commons.dto.UsersDTO;
import it.pecuswap.commons.exceptions.PecuswapRestException;

import java.util.List;

import org.apache.log4j.Logger;

public class UserBusiness {
	
	private static final Logger LOGGER = Logger.getLogger(UserBusiness.class);

	public UsersDTO findUserByUserName(String userName) throws PecuswapRestException, EntityHomeException {
		UsersDelegate delegate = new UsersDelegate(Users.class, false);
	    Users example = new Users();
	    example.setUsername(userName);
	    List<Users> user = delegate.findByExample(example);
	    if (user.size() > 0){
	    	UsersDTO userDTO = new UsersDTO();
	    	userDTO = UserWrapper.copyFromEntity(user.get(0));
	    	return userDTO;
	    } else{
	    	return null;
	    }
    }

}